// JavaScript Document
var xmlHttp
function get_reward() {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("您的瀏覽器不支持AJAX！");
		return;
	}
	var url = "ajax_output.php";
	url = url + "?act=reward";
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function change_skills(val)
{
	document.getElementById('input_count').style.display = 'none';   
	if('' == val)
	{
		return ;
	}
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("您的瀏覽器不支持AJAX！");
		return;
	}
	var url = "ajax_output.php";
	url = url + "?act=skills&skill_id="+val;
	xmlHttp.onreadystatechange = skill_Changed;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function skill_Changed(){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		document.getElementById("skill_container").innerHTML = xmlHttp.responseText;
	}
}	
function get_shiftwork() {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("您的瀏覽器不支持AJAX！");
		return;
	}
	var url = "ajax_output.php";
	url = url + "?act=shiftwork";
	xmlHttp.onreadystatechange = stateChanged_shiftwork;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function del_attachment(id) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("您的瀏覽器不支持AJAX！");
		return;
	}
	var url = "ajax_output.php";
	url = url + "?act=del_attachment&id="+id;
	xmlHttp.onreadystatechange = stateChanged_del_attachment;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChanged_del_attachment() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		var aid = document.getElementById(xmlHttp.responseText);
		var   p   =   aid.parentNode;
    	p.removeChild(aid); 
	}
}
function add_attachment() {
	var rnd = Math.round(Math.random()*10000000).toString();
	var div = document.createElement('div');
	div.setAttribute('id', 'diva_'+rnd);
	
	var file = document.createElement('input');
	file.setAttribute('type', 'file');
	file.setAttribute('name', 'attachment[]');
	var btn = document.createElement('input');
	btn.setAttribute('value', '移除');
	btn.setAttribute('type', 'button');
	btn.setAttribute('onclick', 'remove_attachment("' + 'diva_' + rnd + '");');
	var br = document.createElement('br');
	div.appendChild(file);
	div.appendChild(btn);
	div.appendChild(br);
	document.getElementById("container_attachment").appendChild(div);
}
function stateChanged_shiftwork() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		var rnd = Math.round(Math.random()*10000000).toString();
		var div = document.createElement('div');
		div.setAttribute('id', 'divs_'+rnd);
		
		var btn = document.createElement('input');
		btn.setAttribute('value', '移除');
		btn.setAttribute('type', 'button');
		btn.setAttribute('onclick', 'remove_shiftwork("' + 'divs_' + rnd + '");');
		div.innerHTML = xmlHttp.responseText;
		var br = document.createElement('br');
		div.appendChild(btn);
		div.appendChild(br);
		document.getElementById("container_shiftwork").appendChild(div);
	}
}
function remove_attachment(id)
{
	var i = document.getElementById(id);
	document.getElementById("container_attachment").removeChild(i);
}
function remove_shiftwork(id)
{
	var i = document.getElementById(id);
	document.getElementById("container_shiftwork").removeChild(i);
}
function remove_reward(id)
{
	var i = document.getElementById(id);
	document.getElementById("container_reward").removeChild(i);
}
function stateChanged() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		var rnd = Math.round(Math.random()*10000000).toString();
		var div = document.createElement('div');
		div.setAttribute('id', 'div_'+rnd);
		
		var btn = document.createElement('input');
		btn.setAttribute('value', '移除');
		btn.setAttribute('type', 'button');
		btn.setAttribute('onclick', 'remove_reward("' + 'div_' + rnd + '");');
		div.innerHTML = xmlHttp.responseText;
		var br = document.createElement('br');
		div.appendChild(btn);
		div.appendChild(br);
		document.getElementById("container_reward").appendChild(div);
	}
}
function $(s) {
	return document.getElementById(s);
}
function $$(s) {
	return document.getElementsByName(s);
}
function GetXmlHttpObject() {
	var xmlHttp = null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
